﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using System.Windows.Input;
using GalaSoft.MvvmLight.Messaging;
using RA.UI.Messages;
using GalaSoft.MvvmLight.Command;
using RA.UI.Model;
using GalaSoft.MvvmLight.Ioc;
using RA.Common;

namespace RA.UI.ViewModel
{
    public class MethodsManagerViewModel : ViewModelBase
    {
        public MethodsManagerViewModel()
        {
            Settings = new SettingsViewModel(RA.Common.Settings.Current);

            Messenger.Default.Register<AgentChangedSettingsChangedMessage>(this, (mess) =>
                {
                    BroadCastSettingsChangedToDefaults();
                }
                );
        }

        ICommand _returnToDefaults;
        public ICommand ReturnToDefaults
        {
            get
            {
                if (_returnToDefaults == null)
                    _returnToDefaults = new RelayCommand(() => BroadCastSettingsChangedToDefaults());

                return _returnToDefaults;
            }
        }

        public void BroadCastSettingsChangedToDefaults()
        {
            Messenger.Default.Send(new SettingsChangedMessage(RA.Common.Settings.Current));
            Settings = new SettingsViewModel(RA.Common.Settings.Current);
            RaisePropertyChanged(() => Settings);
        }

        public SettingsViewModel Settings { get; set; }
    }
}
